home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / wnx1091.lzh / BIN2C.C next >
C/C++ Source or Header  |  1991-10-20  |  12KB  |  568 lines

  1. /*********************************************************************/
  2. /* SAMPLE .WNX APPLICATION SKELETON */
  3. /*    portions borrowed from: */
  4. /*    started 5/28/85 R.Z.   Copyright ATARI Corp. 1985 */
  5. /*********************************************************************/
  6. /*********************************************************************/
  7. /* INCLUDE FILES */
  8. /*********************************************************************/
  9. #include <stdio.h>
  10. #include <obdefs.h>
  11. #include <gemdefs.h>
  12. #include <osbind.h>
  13. #include <xesblk.h>
  14. #include <xesdefs.h>
  15. /*********************************************************************/
  16. /* DEFINES */
  17. /*********************************************************************/
  18. #define TRUE 1
  19. #define FALSE 0
  20.  
  21. #define    ACCNAME    "  File Converter "
  22.  
  23. #define WI_KIND        (SIZER|MOVER|FULLER|CLOSER|NAME)
  24.  
  25. #define NO_WINDOW (-1)
  26.  
  27. #define MIN_WIDTH  (2*gl_wbox)
  28. #define MIN_HEIGHT (3*gl_hbox)
  29.  
  30. /*********************************************************************/
  31. /* EXTERNALS                                    */
  32. /*********************************************************************/
  33.  
  34. extern int    gl_apid,_app,errno;
  35. extern long    base,stksize,stack;
  36.  
  37. extern struct __c {
  38.     int *cb_pcontrol;
  39.     int *cb_pglobal;
  40.     int *cb_pintin;
  41.     int *cb_pintout;
  42.     long *cb_padrin;
  43.     long *cb_padrout;
  44. } _c, *_ad_c;
  45.  
  46. extern int control[], global[]; 
  47. extern int_in[], int_out[];
  48. extern long addr_in[], addr_out[];
  49.  
  50. /*********************************************************************/
  51. /* GLOBAL VARIABLES                                */
  52. /*********************************************************************/
  53.  
  54. long    oldstack;
  55.  
  56. int    gl_hchar;
  57. int    gl_wchar;
  58. int    gl_wbox;
  59. int    gl_hbox;    /* system sizes */
  60.  
  61. int     phys_handle;    /* physical workstation handle */
  62. int     handle;        /* virtual workstation handle */
  63. int        wi_handle;    /* window handle */
  64. int        top_window;    /* handle of topped window */
  65.  
  66. int    xdesk,ydesk,hdesk,wdesk;
  67. int    xold,yold,hold,wold;
  68. int    xwork,ywork,hwork,wwork;    /* desktop and work areas */
  69.  
  70. int    msgbuff[8];    /* event message buffer */
  71. int    keycode;    /* keycode returned by event-keyboard */
  72. int    mx,my;        /* mouse x and y pos. */
  73. int    butdown;    /* button state tested for, UP/DOWN */
  74. int    ret;        /* dummy return variable */
  75.  
  76. int    hidden;        /* current state of cursor */
  77.  
  78. int    fulled;        /* current state of window */
  79.  
  80. int    contrl[12];
  81. int    intin[128];
  82. int    ptsin[128];
  83. int    intout[128];
  84. int    ptsout[128];    /* storage wasted for idiotic bindings */
  85.  
  86. int work_in[11];    /* Input to GSX parameter array */
  87. int work_out[57];    /* Output from GSX parameter array */
  88. int pxyarray[10];    /* input point array */
  89.  
  90. int    menu_id;
  91.  
  92. xesparmblk    xparmblk;
  93.  
  94. int    current_type=0;    /* Defaults to C code    */
  95.  
  96. OBJECT    *treeptr;
  97.  
  98. typedef    struct{
  99.         char    dta_res[21];
  100.         char    dta_attrib[1];
  101.         int        dta_time[1];
  102.         int        dta_date[1];
  103.         long    dta_size[1];
  104.         char    dta_name[14];
  105. }newdta;
  106.  
  107. #include    "D:\\WNX_DEV\\WERCS\\CONVERT.H"
  108. #include    "D:\\WNX_DEV\\WERCS\\CONVERT.C"
  109.  
  110. void    wnx_button()
  111. {
  112.         /* Finds out what was clicked on and does what's necessary */
  113.         xes_xformdo(-1,treeptr,xparmblk.WNX_out[5],&xparmblk);
  114.         
  115.         switch(xparmblk.WNX_out[5]){
  116.             case    _C:    {
  117.                 current_type=0;
  118.                 break;
  119.             }
  120.             
  121.             case    _devpac:    {
  122.                 current_type=1;
  123.                 break;
  124.             }
  125.             
  126.             case    _list:    {
  127.                 current_type=2;
  128.                 break;
  129.             }
  130.             
  131.             case    convertit:    {
  132.                     program();
  133.                     treeptr[convertit].ob_state &= ~SELECTED;
  134.                     xes_draw(convertit,1,&xparmblk);
  135.                     break;
  136.             }
  137.         }
  138. }
  139.  
  140. open_vwork()
  141. {
  142. int i;
  143.     for(i=0;i<10;work_in[i++]=1);
  144.     work_in[10]=2;
  145.     handle=phys_handle;
  146.     v_opnvwk(work_in,&handle,work_out);
  147. }
  148.  
  149.  
  150. void prg_acc_startup()
  151. {
  152.         appl_init();
  153.         phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  154.         open_vwork();
  155. }    
  156.  
  157.  
  158. multi()
  159. {
  160.     int event;
  161.  
  162.       while (TRUE) {
  163.   
  164.           /*    currently only messages... could change this to an
  165.                   evnt_mesag call, but I like to keep it open... */
  166.                 event = evnt_multi(MU_MESAG,
  167.                 1,1,1,
  168.                 0,0,0,0,0,
  169.                 0,0,0,0,0,
  170.                 msgbuff,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
  171.  
  172.                 switch(msgbuff[0]){
  173.                     case    AC_OPEN:
  174.                                 program();
  175.                                 break;
  176.                 }
  177.             }
  178. }
  179.  
  180.  
  181. fix_path_name(p_ptr,n_ptr,f_ptr)
  182.         register char    *p_ptr,*n_ptr,*f_ptr;
  183. {
  184.                 while    (*p_ptr)
  185.                     {
  186.                         *f_ptr=*p_ptr;
  187.                         ++f_ptr;
  188.                         ++p_ptr;
  189.                     }
  190.                     
  191.                 while    (*f_ptr!='\\')
  192.                     --f_ptr;
  193.                     
  194.                 ++f_ptr;
  195.                 
  196.                 while    (*n_ptr)
  197.                     {
  198.                         *f_ptr=*n_ptr;
  199.                         ++n_ptr;
  200.                         ++f_ptr;
  201.                     }
  202.         
  203.                 *f_ptr=0;
  204. }
  205.  
  206. stopme()
  207. {        
  208.         if    (_app==-1){
  209.             xparmblk.WNX_tcount=10;
  210.             xes_submit(&xparmblk);
  211.         }
  212. }
  213.  
  214. uc2str(in,begin1)
  215.     unsigned char *in,begin1[];
  216. {
  217.     int    i;
  218.     unsigned char    c[4];
  219.  
  220.         sprintf(c,"%d",*in);
  221.         strcat(begin1,c);
  222. }
  223.  
  224.  
  225. convert2C(f_name,name,size)
  226. char    *f_name;
  227. char    *name[14];
  228. long    size;
  229. {
  230.     char    *in;
  231.     char    filename[144],arrayname[11];
  232.     
  233.     if    (in=(char *)Malloc(size)){
  234.             /* Do the conversion here    */
  235.             int    i,j,inhandle,outhandle;
  236.             long    temp1,temp2,fseekptr=0;
  237.             char    begin1[80],begin2[80],begin3[80],begin4[80];
  238.             
  239.             inhandle    =    Fopen(f_name,0);
  240.             if    (inhandle<0)
  241.                 return    FALSE;
  242.             temp1    =    Fread(inhandle,size,in);
  243.             if    (temp1!=size)    return    FALSE;
  244.             Fclose(inhandle);            
  245.  
  246.             strcpy(filename,f_name);
  247.             
  248.             i=0;
  249.             while    (filename[i])
  250.                 i++;
  251.     
  252.             while    (filename[i]!='\\')
  253.                 i--;
  254.             
  255.             while (filename[i]!='.' & filename[i]!=0)
  256.                 i++;
  257.         
  258.             if    (filename[i+1]!='C' & (current_type==0)){
  259.                     filename[i+1]='C';
  260.                     filename[i+2]=0;
  261.             }
  262.             else if(filename[i+1]!='S' & (current_type==1)){
  263.                     filename[i+1]='S';
  264.                     filename[i+2]=0;
  265.             }
  266.             else{
  267.                     filename[i+1]='O';
  268.                     filename[i+2]='O';
  269.                     filename[i+3]='P';
  270.                     filename[i+4]=0;
  271.             }
  272.  
  273.  
  274.             outhandle    =    Fcreate(filename,0);
  275.  
  276.             if    (outhandle<0)
  277.                 return    FALSE;
  278.                                         
  279.             /* fix the array name up... */
  280.             strcpy(arrayname,name);
  281.             
  282.             i=0;
  283.             while (arrayname[i]!='.' & arrayname[i]!=0)
  284.                 i++;
  285.             
  286.             arrayname[i]=0;
  287.         
  288.             switch    (current_type){
  289.                 case    0:{
  290.                     /* C Declaration    */
  291.  
  292.                     strcpy(begin1,"/* This is a C code representation of the file:\n");
  293.                     
  294.                     strcpy(begin2,"   ");
  295.                     strcat(begin2,f_name);
  296.                     strcat(begin2,"\n");
  297.                     
  298.                     strcpy(begin3,"   ...as an array of unsigned character (bytes) */\n\n");
  299.                     
  300.                     strcpy(begin4,"unsigned char ");
  301.                     strcat(begin4,arrayname);
  302.                     strcat(begin4,"[] = {");
  303.                     
  304.                     break;
  305.                     }
  306.                 case    1:{
  307.                     /* Assembler (DevPac ST) */
  308.                 
  309.                     strcpy(begin1,"; This is an assembler representation of the file:\n");
  310.                     
  311.                     strcpy(begin2,"; ");
  312.                     strcat(begin2,f_name);
  313.                     strcat(begin2,"\n");
  314.                     
  315.                     strcpy(begin3,"; ...as an array of bytes.\n\n");
  316.                     
  317.                     strcpy(begin4,arrayname);
  318.                     strcat(begin4,":");
  319.                     
  320.                     break;
  321.                     }
  322.                 case    3:{
  323.                 
  324.                     begin1[0]=0;
  325.                     begin2[0]=0;
  326.                     begin3[0]=0;
  327.                     begin4[0]=0;
  328.                 
  329.                     break;
  330.                     }
  331.                 }
  332.  
  333.             temp2=(long)strlen(begin1);
  334.             if    (temp2!=(Fwrite(outhandle,temp2,begin1)))
  335.                 return FALSE;
  336.             Fclose(outhandle);
  337.             fseekptr    +=    temp2;
  338.  
  339.             outhandle    =    Fopen(filename,2);
  340.             if    (outhandle<0)    return    FALSE;
  341.             temp2=(long)strlen(begin2);
  342.             Fseek(fseekptr,outhandle,0);
  343.             Fwrite(outhandle,temp2,begin2);
  344.             Fclose(outhandle);
  345.             fseekptr    +=    temp2;
  346.             
  347.             outhandle    =    Fopen(filename,2);
  348.             if    (outhandle<0)    return    FALSE;
  349.             temp2=(long)strlen(begin3);
  350.             Fseek(fseekptr,outhandle,0);
  351.             Fwrite(outhandle,temp2,begin3);
  352.             Fclose(outhandle);
  353.             fseekptr    +=    temp2;
  354.  
  355.             outhandle    =    Fopen(filename,2);
  356.             if    (outhandle<0)    return    FALSE;
  357.             temp2=(long)strlen(begin4);
  358.             Fseek(fseekptr,outhandle,0);
  359.             Fwrite(outhandle,temp2,begin4);            
  360.             Fclose(outhandle);
  361.             fseekptr    +=    temp2;
  362.             
  363.             j=0;
  364.             for(i=0;i<size;i++){
  365.  
  366.                 /* Every 18 entries, skip to a new line...    */            
  367.  
  368.                 if    ((i%18)==0){
  369.                     if(i){
  370.  
  371.                         outhandle    =    Fopen(filename,2);
  372.                         if    (outhandle<0)    return    FALSE;
  373.                         temp2=(long)strlen(begin1);
  374.                         Fseek(fseekptr,outhandle,0);
  375.                         Fwrite(outhandle,temp2,begin1);
  376.                         Fclose(outhandle);
  377.                         fseekptr    +=    temp2;
  378.                     
  379.